#include<bits/stdc++.h>
using namespace std;

//definition for a binary tree node.
struct TreeNode {
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

class Solution {
public:
	vector<int> inorderTraversal(TreeNode* root) {
		if (!root) return{};
		stack<TreeNode*>stack;
		vector<int> val;
		TreeNode* cur = root;
		while (cur || !stack.empty()) {
			while (cur) {
				stack.push(cur);
				cur = cur->left;
			}
			cur = stack.top();
			stack.pop();
			val.push_back(cur->val); 
			cur = cur->right;
		}
		return val;
	}
};